<!doctype html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <!-- <style>
        .details{
            width: 400px;
            height: 200px;
            border: 1px solid red;
            position:fixed;

        }
    </style> -->
</head>
<body>
<!--header start -->
{include file="header"}
<!--header end-->

<!-- <div class="details"></div> -->
<table class="weui-table weui-border-tb" id="cusTable">
    <thead>
    <tr>

        <th  data-field="username" style="border-left:2px solid #fff">新闻标题</th>
        <th>新闻图片</th>
        <!-- <th>新闻内容</th> -->
        <th>作者</th>
        <th>发布时间</th>
        <th>banner图</th>
        <th>banner状态</th>
        <th>新闻状态</th>
        <th>是否头条</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>

    {volist name="data" id="vo"}
        <tr>
            <td data-field="" id="sub" style="border-left:2px solid #fff">{$vo.news_title}</td>
            <td><a href="{:url('News/news_img',array('id'=>$vo.id))}"><img src="/vdma/public/uploads/{$vo.news_img}" style="width: 50px"></a></td>
            <!-- <td>
                <a href="###" data-id="{$vo.id}" onclick="details(this)">详情</a>
            </td> -->
            <td>{$vo.author}</td>
            <th>{$vo.news_time}</th>
            <td>
                {if condition="($vo.news_banner == '')"}
                <a href="{:url('News/news_banner',array('id'=>$vo.id))}">banner图</a>
                {else /}
                <a href="{:url('News/news_banner',array('id'=>$vo.id))}"><img src="/vdma/public/uploads/{$vo.news_banner}" style="width: 50px"></a>
                {/if}
                <!-- <a href="{:url('News/news_banner',array('id'=>$vo.id))}"><img src="/vdma/public/uploads/{$vo.news_banner}" style="width: 50px"></a> -->

            </td>
            <td><a href="###" onclick="changebanner(this)" data-id="{$vo.id}" banner_statuid="{$vo.banner_statuid}"><span>{$vo.banner_statuid == 1?'显示':'隐藏'}</span></a></td>
            <th><a href="###" onclick="changenews(this)" data-id="{$vo.id}" news_statuid="{$vo.news_statuid}"><span>{$vo.news_statuid?'正常':'失效'}</span></a></th>
            <th>
                <a href="###" onclick="changeheadlines(this)" data-id="{$vo.id}" headlines="{$vo.headlines}"><span>{$vo.headlines == 1?'是':'否'}</span></a>
            </th>
            <th>
                <a href="{:url('edit',array('id'=>$vo.id))}" id="edit" data-id="{$vo.id}"><span class="icon icon-115" title="编辑">编辑</span></a>
                <a href="###" id="delete" data-id="{$vo.id}" onclick="del(this)"><span class="icon icon-23"  title="删除">删除</span></a>
            </th>
        </tr>
    {/volist}

    </tbody>

</table>


<div class="pages">{$page}</div>
<!--footer start -->
{include file="footer"}
<!--footer end-->
<script>
//    删除
    function del(_this){
        var uid = $(_this).attr('data-id');
        $.ajax({
            type:'post',
            url:"{:url('News/delete')}",
            data:{'uid':uid},
            success:function(data){

                switch(data){
                    case 1:
                        $(_this).parent().parent().remove();
                        break;
                    case 2:
                        alert('删除失败');
                        break;
                    case 3:
                        alert('用户不存在');
                        break;
                    case 4:
                        alert('请求格式不对');
                        break;
                }
            }
        })
    }

    // //详情
    // function details(_this){
    //     var uid = $(_this).attr('data-id');
    //     $.ajax({
    //         type:'post',
    //         url:"{:url('News/details')}",
    //         data:{'id':uid},
    //         success:function(data){
    //             switch(data){
    //                 case 2:
    //                     alert('新闻不存在');
    //                     break;
    //                 case 3:
    //                     alert('请求格式不对');
    //                     break;
    //                 default:
    //                     $('.details').empty();
    //                     $('.details').css({'display':'list-item'});
    //                     var details = "<P>"+data+"<p>";
    //                     $('.details').append(details);
    //             }
    //         }
    //     })
    // }

//修改banner状态
function changebanner(_this){
    var banner_statuid = $(_this).attr('banner_statuid');
    var uid = $(_this).attr('data-id');

    $.ajax({
        type:'post',
        url:"{:url('News/changebanner')}",
        data:{'banner_statuid':banner_statuid,'id':uid},
        success:function(data){
            if(data.msg == '修改成功'){
                if(data.statuid == 1){
                    $(_this).find('span').text('显示');
                    $(_this).attr('banner_statuid',1);

                }else{
                    $(_this).find('span').text('隐藏');
                    $(_this).attr('banner_statuid',0);

                }

            }
        }
    })
}


//修改新闻状态
function changenews(_this){
    var news_statuid = $(_this).attr('news_statuid');
    var uid = $(_this).attr('data-id');

    $.ajax({
        type:'post',
        url:"{:url('News/changenews')}",
        data:{'news_statuid':news_statuid,'id':uid},
        success:function(data){
            if(data.msg == '修改成功'){
                if(data.statuid == 1){
                    $(_this).find('span').text('正常');
                    $(_this).attr('news_statuid',1);

                }else{
                    $(_this).find('span').text('失效');
                    $(_this).attr('news_statuid',0);

                }

            }
        }
    })
}


//修改头条状态
function changeheadlines(_this){
    var id = $(_this).attr('data-id');
    var headlines = $(_this).attr('headlines');

    $.ajax({
        type:'post',
        url:"{:url('headlines')}",
        data:{'id':id,'headlines':headlines},
        success:function(data){
            console.log(data);
            if(data.code == 1){
                if(data.headlines == 1){
                    $(_this).find('span').text('是');
                    $(_this).attr('headlines',1);

                }else{
                    $(_this).find('span').text('否');
                    $(_this).attr('headlines',0);

                }
            }else{
                alert(data.msg);
            }
        }
    })
}
</script>
</body>
</html>